$(function(){
	
	$("#edit-resource-type").attr("readonly","readonly");
	$("#edit-resource-name").attr("readonly","readonly");
	//点击“编辑--保存”按钮
	$("#edit-resource-btn").click(function() {
		var edit = document.getElementById("edit-resource-btn").value;
		if(edit=="编辑") {
			$(".resourceEdit button").show();
			$(".important-link").hide();
			$("#edit-resource-name").attr("contenteditable",true);
			$("#edit-resource-name").css("border","0.1rem solid gray");
			document.getElementById("edit-resource-btn").value = "保存";
		} else if(edit=="保存") {
			/*更新*/
			$(".resourceEdit button").hide();
			$(".important-link").show();
			$("#edit-resource-name").attr("contenteditable",false);
			$("#edit-resource-name").css("border","0");
			document.getElementById("edit-resource-btn").value = "编辑";
		}
	});
	
	//点击“发布任务”按钮
	$("#publish-resource-btn").click(function() {
		var resourceId=$("input[name='resourceId']").val();
		var resourceType = $("input[name='hiddenType']").val();
		
		//TODO
		if(resourceType == "课程资源"){
			//课程资源直接发布
			
		}else{
			//课堂资源进入选择课堂发布页面
			/*window.location.href=CONTEXT_PATH+""*/
		}
		// for test & delete later
		window.location.href=CONTEXT_PATH+"teapage/courseResourcePublish.jsp";
	});
	$("#resource-file-list-edit").on("click",".btn",function() {
		$(this).closest("li").remove();
		return false;
	});
});
function resourceFileListEdit() {
	var list = $("#resource-file-list-edit");
	var obj = document.getElementById("resource-file-edit");
	var len = obj.files.length;
	console.log(len);
	for (var i = 0; i < len; i++) {
		var temp ="";
		
		temp += ("<li><span>" + obj.files[i].name + "</span>");
		temp += ("<a href=\"下载地址\" class=\"important-link\" style=\"display:none;\">下载</a><button type=\"button\" style=\"display:block;\" class=\"btn btn-default\">删除</button></li>");
		
		list.append(temp);
	}
	addAttachment('attach');
}